﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Shared/TabPage.Master" AutoEventWireup="true"
    CodeBehind="DetrImport.aspx.cs" Inherits="eTerm.Platform.Web.PNR.DetrImport" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

    <script src="../Scripts/uploadify/jquery.uploadify.min.js" type="text/javascript"></script>

    <link href="../Scripts/uploadify/uploadify.css" rel="stylesheet" type="text/css" />

    <script language="javascript" type="text/javascript">
        $(function() {
            $("#uploadify").uploadify({
                'height': 30,
                'swf': '../Scripts/uploadify/uploadify.swf',
                'uploader': '../ISAPI/uploadify.ashx',
                'width': 120,
                'folder': 'upload',
                'cancelImg': '../Scripts/uploadify/uploadify-cancel.png',
                'auto': false,
                'multi': false,
                'fileTypeDesc': '支持的格式：',
                //允许上传的文件后缀
                'fileTypeExts': '*.xls;',
                //上传文件的大小限制
                'fileSizeLimit': '3MB',
                'onUploadSuccess': function(file, data, response) {
                    //alert(eval(data));
                    $('#tbDetr').datagrid('loadData', $.parseJSON(data));
                    $("a.icon-delete2").show();
                    $.jBox.tip('Excel票号导入完毕。', 'info');
                },
                //返回一个错误，选择文件的时候触发
                'onSelectError':function(file, errorCode, errorMsg){
                    switch(errorCode) {
                        case -100:
                            alert("上传的文件数量已经超出系统限制的"+$('#uploadify').uploadify('settings','queueSizeLimit')+"个文件！");
                            break;
                        case -110:
                            alert("文件 ["+file.name+"] 大小超出系统限制的"+$('#uploadify').uploadify('settings','fileSizeLimit')+"大小！");
                            break;
                        case -120:
                            alert("文件 ["+file.name+"] 大小异常！");
                            break;
                        case -130:
                            alert("文件 ["+file.name+"] 类型不正确！");
                            break;
                        }
                },
                'onOpen': function(event, ID, fileObj) {
                    $.jBox.tip('正在处理票号文件' + fileObj.name + "......", 'loading');
                }
                //'fileTypeExts'  : '*.xls; *.xlsx',
            });



            $('#tbDetr').datagrid({
                idField: 'ID',
                columns: [[
                            { field: 'ID', title: '编号', checkbox: true },
                            { field: 'TicketNo', title: '票号', width: 200 },
                            { field: 'TicketDate', title: '出票日期', width: 100, align: 'right' }
                        ]]
            });

        });
        
        
         /**
         * 批量操作
         * @return
         */
        function batch(){
            if($('#tbDetr').datagrid('getSelected')){
                //首先如果用户选择了数据，则获取选择的数据集合
                var ids = [];
                var cods = [];
                var selectedRow = $('#tbDetr').datagrid('getSelections');
                for (var i = 0; i < selectedRow.length; i++) {
                    var deleteRow = $('#tbDetr').datagrid('getRowIndex', selectedRow[i]);
                    //$('#tbDetr').datagrid('deleteRow', deleteRow);
                    cods.push(deleteRow);
                    ids.push(selectedRow[i].ID);
                }
            }else{
                $.jBox.tip("请选择需要处理的数据行！", "error");
                return;
            }
            for (var i = 0; i < cods.length; i++)
                $('#tbDetr').datagrid('deleteRow', cods[i]);
            var userid = ids.join(',');
            $.post("../ISAPI/DeleteDETR.ashx",{"ID":userid},function(){
                $.jBox.tip("数据已被处理。", "success");
            });
        }


    </script>

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpButtons" runat="server">
    <span class="icon icon-edit">&nbsp;</span><a href="javascript:void(null);" onclick="javascript:$('#uploadify').uploadify('upload', '*');return false;">从Excel导入</a>
    <span class="icon icon-delete2">&nbsp;</span><a href="javascript:void(null);" onclick="javascript:batch();return false;">删除</a>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cpContent" runat="server">
    <input type="file" name="uploadify" id="uploadify" />
    <table id="tbDetr">
    </table>
</asp:Content>
